Skip to content

Fix empty samplers and logits_processors not filtered in GenerationBatch.filter - #1772

Merged
zcbenz merged 2 commits into
ml-explore:mainfrom
geekybraindev:fix-generation-batch-filter
Aug 25, 2026
Merged

zcbenz merged 2 commits into
ml-explore:mainfrom
geekybraindev:fix-generation-batch-filter

Conversation

@geekybraindev

Copy link
Copy Markdown

GenerationBatch.filter prunes its per-sequence samplers and logits_processors lists only if any(...). A request with no processors leaves an empty entry, any([[]]) is False, and the finished request's entry survives the prune. The next request that does carry a processor is then appended under the wrong index: its processor runs on the batch's own first step and never again. The same happens to a per-request sampler after a request without one.

In mlx_lm.server this shows up as a logits_processors / response_format-style request being honored only when it is the first request to a fresh server; after any plain request, later constrained requests come back unconstrained, with no error.

PromptProcessingBatch.filter already handles this with an else branch. This applies the same fix to GenerationBatch.filter and adds test_batch_processors_and_samplers_survive_a_request_without_them, which fails on main and passes with the fix.

Disclosure per CONTRIBUTING: the fix and test were written with Claude Code and this description was drafted by it, under my direction; I reproduced the bug and the fix on a served model and take responsibility for every line.

@nastya236 nastya236 added the bug label Aug 24, 2026
geekybraindev and others added 2 commits August 25, 2026 19:36
…ch.filter

GenerationBatch.filter pruned its per-sequence `samplers` and
`logits_processors` lists only `if any(...)`. A request with no
processors leaves an empty entry, `any([[]])` is False, and the finished
request's entry survives the prune. The next request that does carry a
processor is then appended under the wrong index: its processor runs on
the batch's own first step and never again (the same for a per-request
sampler after a request without one). In mlx_lm.server this shows up as
a response_format / logits_processors request being honored only when it
is the first request to a fresh server.

PromptProcessingBatch.filter already handles this with an `else` branch;
this applies the same fix to GenerationBatch.filter and adds a test that
fails on main and passes with the fix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@zcbenz
zcbenz force-pushed the fix-generation-batch-filter branch from 6a25cdd to c6062cc Compare August 25, 2026 10:37
@zcbenz zcbenz changed the title Prune samplers and logits_processors unconditionally in GenerationBatch.filter Fix empty samplers and logits_processors not filtered in GenerationBatch.filter Aug 25, 2026
@zcbenz
zcbenz merged commit e2f2fb2 into ml-explore:main Aug 25, 2026
2 checks passed
azamamirza added a commit to azamamirza/mlx-lm that referenced this pull request Aug 27, 2026
Rebased onto upstream/main 74e7cf9 (adds ml-explore#1673 ChunkedKVCache valid-length
trim — which supersedes and retires our own fix — plus ml-explore#1772 GenerationBatch
filter, ml-explore#1775 decode-loop thread-safety, and new model support). Our two
qwen3_moe patches (tensor-parallel ml-explore#1774 submitted, pipeline staged) ride on
top unchanged and rebased clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants